/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-05-27 16:43:15
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-07-29 10:02:17
 * @FilePath: /vue3-uniapp/src/other/componentsResolvers/tuniaoUiResolver.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import type {
    ComponentResolver,
    SideEffectsInfo
} from 'unplugin-vue-components';

const camelToKebab = (str: string) => {
    return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
};
// let isFirst = true;
export const tuniaoUiResolver = (): ComponentResolver[] => {
    return [
        {
            type: 'component',
            resolve: (name: string) => {
                if (!/^Tn[A-Z]\w*$/i.test(name)) {
                    return;
                }
                const componentName = camelToKebab(name.replace(/^Tn/, ''));
                // let sideEffects: SideEffectsInfo;
                // if (isFirst) {
                //     sideEffects = {
                //         from: '@tuniao/tn-style/dist/uniapp/index.css'
                //     };
                //     isFirst = false;
                // }
                if (componentName === 'color-select') {
                    return {
                        name: 'default',
                        from: 'tnuiv3p-tn-color-select/index.vue'
                    };
                }
                if (componentName.indexOf('item') !== -1) {
                    const matchName = componentName.match(/(.*)-item$/)![1];
                    return {
                        name: 'default',
                        from: `@tuniao/tnui-vue3-uniapp/components/${matchName}/src/${componentName}.vue`
                    };
                }
                return {
                    name: 'default',
                    from: `@tuniao/tnui-vue3-uniapp/components/${componentName}/src/${componentName}.vue` // uniapp通过后缀添加usingComponents,ts文件或无后缀文件不会生成
                    // sideEffects: {
                    //     from: '@tuniao/tn-style/dist/uniapp/index.css'
                    // }
                };
            }
        }
    ];
};
